package com.training.admin.entity.project;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;
import com.training.admin.entity.trainee.Trainee;


/**
 * 培训结果
 * @author Rockett
 *
 */
@Entity
@Table(name = "training_result")
public class TrainingResult {
    
	/**
	 * ID
	 */
    @Id
    @GeneratedValue
    private Long id;
    
    /**
     * 项目-期
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private ProjectPhase projectPhase;
    
    /**
     * 学员
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Trainee trainee;

    /**
     * 记录日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date submitDate;
    
    /**
     * 备注
     */
    private String comment;
	/**
     * 成绩
     */
    private Float score;
    
    /**
     * 缺勤天数
     */
    private Float absence;
    
    /**
     * 是否补考
     */
    @Column(name = "is_resit")
    private boolean resit;
   
    
    //非人类项目
    /**
     * 现场笔试成绩
     */
    
    private Float spotScore;
    
    /**
     * 面试官认证次数
     */
    private Integer interviewerCertifyTimes;
    
    /**
     * 面试官认证
     */
    private String interviewerCertification;
    /**
     * 辅导师认证次数
     */
    private Integer counselorCertifyTimes;
    
    /**
     * 辅导师认证
     */
    private String counselorCertification;
    
    /**
     * 是否种子
     */
    private String seed;
    
    /** 是否被浏览过 */
    @Column(name = "is_scanned")
    public boolean scanned;

	/**
     * The default constructor
     */
    public TrainingResult() {
    }
    
    /**
     * 
     * @param email
     * @param score
     * @param absence
     * @param resit
     * @param comment
     */
    public TrainingResult(String email, String score, String absence, String resit, String comment) {
    	this.trainee = new Trainee(email);
    	this.score =  StringUtils.isEmpty(score) ? null : Float.valueOf(score);
    	this.absence =  Float.valueOf(absence);
    	this.resit = resit.equals("是") ? true : false;
    	this.comment = comment;
    }
    
    public TrainingResult(Trainee trainee, Float score, Float absence, Boolean resit, String comment) {
    	this.trainee = trainee;
    	this.score =  score;
    	this.absence = absence;
    	this.resit = resit;
    	this.comment = comment;
    }
    /**
     * 
     * @param projectPhaseId
     * @return
     */
    public TrainingResult(ProjectPhase projectPhaseId, TrainingResult trainingResult, Trainee trainee) {
    	this.projectPhase=projectPhaseId;
    	this.trainee = trainee;
    	this.submitDate = new Date();
    	this.score = trainingResult.getScore();
    	this.absence= trainingResult.getAbsence();
    	this.resit = trainingResult.isResit();
    	this.comment = trainingResult.getComment();
    	this.scanned = false;
    } 
    
    /**
     * @param projectTrainee
     * @param projectPhase
     */
    public TrainingResult(ProjectTrainee projectTrainee, Trainee trainee, ProjectPhase projectPhase, Long projectCategoryId) {
        this.trainee = trainee;
        this.projectPhase = projectPhase;
        this.submitDate = new Date();
        this.score =  projectTrainee.getScore();
        this.absence = projectTrainee.getAbsence();
        this.resit = projectTrainee.getResit();
        this.comment = projectTrainee.getComment();
        if(projectCategoryId == 15 || projectCategoryId == 16) {
            this.interviewerCertifyTimes = projectTrainee.getInterviewTimes() == null ? 0 : projectTrainee.getInterviewTimes();
            this.spotScore = projectTrainee.getSpotScore();
            this.interviewerCertification = projectTrainee.getInterview();
            this.counselorCertifyTimes = projectTrainee.getCounselorTimes();
            this.counselorCertification = projectTrainee.getCounselor();
            this.seed = projectTrainee.getSeed();
        }
    }
    
    /**
     * 
     * @param projectTrainee
     * @param projectPhase
     */
    public TrainingResult(ProjectTrainee projectTrainee, ProjectPhase projectPhase) {
        this.trainee = projectTrainee.getTrainee();
        this.projectPhase = projectPhase;
        this.submitDate = new Date();
        this.score =  projectTrainee.getScore();
        this.absence = projectTrainee.getAbsence();
        this.resit = projectTrainee.getResit();
        this.comment = projectTrainee.getComment();
        this.interviewerCertifyTimes = projectTrainee.getInterviewTimes() == null ? 0 : projectTrainee.getInterviewTimes();
        this.spotScore = projectTrainee.getSpotScore();
        this.interviewerCertification = projectTrainee.getInterview();
        this.counselorCertifyTimes = projectTrainee.getCounselorTimes() == null ? 0 : projectTrainee.getCounselorTimes();
        this.counselorCertification = projectTrainee.getCounselor();
        this.seed = projectTrainee.getSeed();
    }

    /**
     * @param projectTrainee
     * @return
     */
    public TrainingResult updateByProjectTrain(ProjectTrainee projectTrainee, Long projectCategoryId) {
        this.submitDate = new Date();
        this.score =  projectTrainee.getScore();
        this.absence = projectTrainee.getAbsence();
        this.resit = projectTrainee.getResit();
        this.comment = projectTrainee.getComment();
        if(projectCategoryId == 15 || projectCategoryId == 16) {
            this.interviewerCertifyTimes = projectTrainee.getInterviewTimes();
            this.spotScore = projectTrainee.getSpotScore();
            this.interviewerCertification = projectTrainee.getInterview();
            this.counselorCertifyTimes = projectTrainee.getCounselorTimes();
            this.counselorCertification = projectTrainee.getCounselor();
            this.seed = projectTrainee.getSeed();
        }
        return this;
    }
    
    /**
     * 
     * @param projectTrainee
     * @return
     */
    public TrainingResult updateByProjectTrain(ProjectTrainee projectTrainee) {
        this.submitDate = new Date();
        this.score =  projectTrainee.getScore();
        this.absence = projectTrainee.getAbsence();
        this.resit = projectTrainee.getResit();
        this.comment = projectTrainee.getComment();
        this.interviewerCertifyTimes = projectTrainee.getInterviewTimes() == null ? 0 : projectTrainee.getInterviewTimes();
        this.spotScore = projectTrainee.getSpotScore();
        this.interviewerCertification = projectTrainee.getInterview();
        this.counselorCertifyTimes = projectTrainee.getCounselorTimes();
        this.counselorCertification = projectTrainee.getCounselor();
        this.seed = projectTrainee.getSeed();
        return this;
    }
    
    /**
     * 
     * @param score
     * @param absence
     * @param resit
     * @param comment
     * @return
     */
    public TrainingResult upload(Float score, Float absence, Boolean resit, String comment) {
    	this.score = score;
    	this.absence = absence;
    	this.resit = resit;
    	this.comment =comment;
		return this;
    }
    
    /**
     * 
     * @param projectPhase
     * @return
     */
    public TrainingResult inputResult(ProjectPhase projectPhase) {
    	this.projectPhase = projectPhase;
    	this.submitDate = new Date();
    	return this;
    }
    
    /**
     * @return
     */
    public TrainingResult setToScanned() {
        this.scanned = true;
        return this;
    }

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the projectPhase
	 */
	public ProjectPhase getProjectPhase() {
		return projectPhase;
	}

	/**
	 * @return the trainee
	 */
	public Trainee getTrainee() {
		return trainee;
	}

	/**
	 * @return the submitDate
	 */
	public Date getSubmitDate() {
		return submitDate;
	}

	/**
	 * @return the comment
	 */
	public String getComment() {
		return comment;
	}

	/**
	 * @return the score
	 */
	public Float getScore() {
		return score;
	}

	/**
	 * @return the absence
	 */
	public Float getAbsence() {
		return absence;
	}

	/**
	 * @return the resit
	 */
	public boolean isResit() {
		return resit;
	}

	/**
	 * @return the spotScore
	 */
	public Float getSpotScore() {
		return spotScore;
	}

	/**
	 * @return the interviewerCertifyTimes
	 */
	public Integer getInterviewerCertifyTimes() {
		return interviewerCertifyTimes;
	}

	/**
	 * @return the interviewerCertification
	 */
	public String getInterviewerCertification() {
		return interviewerCertification;
	}

	/**
	 * @return the counselorCertifyTimes
	 */
	public Integer getCounselorCertifyTimes() {
		return counselorCertifyTimes;
	}

	/**
	 * @return the counselorCertification
	 */
	public String getCounselorCertification() {
		return counselorCertification;
	}

	/**
	 * @return the seed
	 */
	public String getSeed() {
		return seed;
	}
	
	/**
     * @return the scanned
     */
    public boolean isScanned() {
        return scanned;
    }

    /**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param projectPhase the projectPhase to set
	 */
	public void setProjectPhase(ProjectPhase projectPhase) {
		this.projectPhase = projectPhase;
	}

	/**
	 * @param trainee the trainee to set
	 */
	public void setTrainee(Trainee trainee) {
		this.trainee = trainee;
	}

	/**
	 * @param submitDate the submitDate to set
	 */
	public void setSubmitDate(Date submitDate) {
		this.submitDate = submitDate;
	}

	/**
	 * @param comment the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}

	/**
	 * @param score the score to set
	 */
	public void setScore(Float score) {
		this.score = score;
	}

	/**
	 * @param absence the absence to set
	 */
	public void setAbsence(Float absence) {
		this.absence = absence;
	}

	/**
	 * @param resit the resit to set
	 */
	public void setResit(boolean resit) {
		this.resit = resit;
	}

	/**
	 * @param spotScore the spotScore to set
	 */
	public void setSpotScore(Float spotScore) {
		this.spotScore = spotScore;
	}

	/**
	 * @param interviewerCertifyTimes the interviewerCertifyTimes to set
	 */
	public void setInterviewerCertifyTimes(Integer interviewerCertifyTimes) {
		this.interviewerCertifyTimes = interviewerCertifyTimes;
	}

	/**
	 * @param interviewerCertification the interviewerCertification to set
	 */
	public void setInterviewerCertification(String interviewerCertification) {
		this.interviewerCertification = interviewerCertification;
	}

	/**
	 * @param counselorCertifyTimes the counselorCertifyTimes to set
	 */
	public void setCounselorCertifyTimes(Integer counselorCertifyTimes) {
		this.counselorCertifyTimes = counselorCertifyTimes;
	}

	/**
	 * @param counselorCertification the counselorCertification to set
	 */
	public void setCounselorCertification(String counselorCertification) {
		this.counselorCertification = counselorCertification;
	}

	/**
	 * @param seed the seed to set
	 */
	public void setSeed(String seed) {
		this.seed = seed;
	}

    /**
     * @param scanned the scanned to set
     */
    public void setScanned(boolean scanned) {
        this.scanned = scanned;
    }

}